package com.erp.myAdapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.erp.module.dingDan.prodyctionClient.ProdyctionClientActivity
import com.erp.bean.ZhiLiangBean
import com.erp.R
import com.erp.mclass.QuanXian
import com.erp.module.zhiLiang.ZhiLiangContract
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_wuliao_zhiliang.view.*

/**
 * Created by Administrator on 2018/2/1/001.
 * 作者：刘洋
 */

class ZhiLiangAdapter(private val mlist: List<ZhiLiangBean>, private val mcontext: Context,private  val V :ZhiLiangContract.ZhiLiangView) : BaseAdapter() {
    private val minflater: LayoutInflater

    init {
        this.minflater = LayoutInflater.from(mcontext)

    }

    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(position: Int): Any {
        return mlist[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        var convertView = convertView
        val v: ViewHolder
        if (convertView == null) {
            convertView = minflater.inflate(R.layout.lv_wuliao_zhiliang, null)
            v = ViewHolder(convertView)
            convertView.tag = v
        } else {
            v = convertView.tag as ViewHolder
        }
        val bean = mlist[position]
        Myutil.settv(bean.mcode, v.tvTiaoma)
        val name = bean.work_number + "  " + bean.wu_name
        Myutil.settv(name, v.tvGonghao)
        Myutil.settv(Myutil.getdata(bean.occurrence_time), v.tvFashengTime)
        Myutil.settv(Myutil.getdata(bean.ctime), v.tvChuangjianTime)
        Myutil.settv(Myutil.getdata(bean.qi_name), v.tvWenti)
        Myutil.settv(bean.handle_way, v.tvWentizhuangtai)
        Myutil.settv(bean.description, v.tvWentiMiaoshu)
        Myutil.settv(bean.solution, v.tvChuli)
        Myutil.settv(bean.creator_name, v.tvShangchuanname)
        val s = bean.bu_men + "   " + bean.han_qu + "   " + bean.che_jian + "   " + bean.zu_bie
        Myutil.settv(s, v.tvchangQuName)
        Myutil.settv(bean.ts, v.tvCishu)
        Myutil.settv(Myutil.getdata(bean.consignee_time), v.tvConsigneeTime)
        Myutil.settv(bean.consignee_name, v.tvConsigneeName)
        v.tvDanhao.text = "订单详情"
        v.tvDanhao.setOnClickListener {
            val intent = Intent(mcontext, ProdyctionClientActivity::class.java)
            intent.putExtra("id", bean.oid)
            intent.putExtra("selsct", 2)
            intent.putExtra("all", "")
            mcontext.startActivity(intent)
        }
        if(QuanXian.isConsigneeMaterialQuality && bean.consignee_time == "" && bean.handle_way == "补板"){
            v.btShouhuo.visibility = View.VISIBLE
        }else{
            v.btShouhuo.visibility = View.GONE
        }
        v.btShouhuo.setOnClickListener{
            V.shouhuo(bean.id)
        }
        return convertView
    }

    internal class ViewHolder(view: View) {
        var tvTiaoma=view.tv_tiaoma
        var tvGonghao=view.tv_gonghao
        var tvFashengTime=view.tv_fasheng_time
        var tvChuangjianTime=view.tv_chuangjian_time
        var tvWenti=view.tv_wenti
        var tvWentizhuangtai=view.tv_wentizhuangtai
        var tvWentiMiaoshu=view.tv_wenti_miaoshu
        var tvDanhao=view.tv_danhao
        var tvChuli=view.tv_chuli
        var tvShangchuanname=view.tv_shangchuanname
        var tvchangQuName=view.changQuNameTv
        var tvCishu=view.tv_cishu
        var tvConsigneeTime=view.tv_consignee_time
        var tvConsigneeName=view.tv_consignee_name
        var btShouhuo = view.Tvshouhuo;
    }
}
